package org.gg.boom.kernel.config.factory;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.gg.boom.common.utils.ServletUtils;

import java.util.Objects;

public class PageFactory {
    private static final String PAGE_SIZE_PARAM = "pageSize";
    private static final String PAGE_NUM_PARAM = "pageNum";

    public static <T> Page<T> defaultPage() {
        int pageSize = 10;
        int pageNum = 1;
        Integer size = ServletUtils.getParameterToInt(PAGE_SIZE_PARAM);
        if (Objects.nonNull(size)) {
            pageSize = size;
        }
        Integer num = ServletUtils.getParameterToInt(PAGE_NUM_PARAM);
        if (Objects.nonNull(num)) {
            pageNum = num;
        }
        return new Page<>(pageNum, pageSize);
    }
}
